#pragma semicolon 1
#pragma newdecls required

#include <sourcemod>
#include <sdktools>

public Plugin myinfo = 
{
    name = "l4d2_admin_target_delete",
    author = "豆瓣酱な",
    description = "允许管理员删除他们瞄准的物体",
    version = "1.0",
    url = "https://gitee.com/sweet-and-sour-bombs/adfvsdsd"
};

public void OnPluginStart()
{
    RegAdminCmd("sm_dtg", Command_DeleteTarget, ADMFLAG_ROOT, "删除你瞄准的物体");
}

public Action Command_DeleteTarget(int client, int args)
{
    if (!client)
    {
        ReplyToCommand(client, "此命令只能在游戏中执行");
        return Plugin_Handled;
    }
    
    if (!IsClientInGame(client))
    {
        ReplyToCommand(client, "你必须在游戏中才能使用此命令");
        return Plugin_Handled;
    }
    
    int entity = GetClientAimTarget(client, false);
    
    if (entity == -1)
    {
        ReplyToCommand(client, "你没有瞄准任何有效的物体");
        return Plugin_Handled;
    }
    
    char classname[64];
    if (!GetEntityClassname(entity, classname, sizeof(classname)))
    {
        ReplyToCommand(client, "无法获取物体的类名");
        return Plugin_Handled;
    }
    
    if (AcceptEntityInput(entity, "Kill"))
    {
        PrintToChat(client, "成功删除物体: %s", classname);
    }
    else
    {
        PrintToChat(client, "删除物体失败: %s", classname);
    }
    
    return Plugin_Handled;
}
